package com.tianji.learning.controller;

import com.tianji.common.domain.dto.PageDTO;
import com.tianji.learning.domain.Vo.LearningNoteVO;
import com.tianji.learning.domain.dto.AddNoteDTO;
import com.tianji.learning.domain.dto.LearningNoteFromDTO;
import com.tianji.learning.domain.query.NoteQuery;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;
import com.tianji.learning.service.ILearningNoteService;
import com.tianji.learning.domain.po.LearningNote;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 笔记表 控制器
 * </p>
 *
 * @author author
 */
@Api(tags = "LearningNote管理")
@RestController
@RequiredArgsConstructor
@RequestMapping("/notes")
public class LearningNoteController {

    private final ILearningNoteService learningNoteService;
    @ApiOperation("笔记回显")
    @GetMapping("/{id}")
    public LearningNoteVO getNoteById(@PathVariable Long id){
        return learningNoteService.getNoteById(id);
    }

    @PostMapping
    public void insertNote(@RequestBody AddNoteDTO dto){
        learningNoteService.insertNote(dto);
    }
    @ApiOperation("更新笔记")
    @PutMapping("/{id}")
    public void updateNote(
            @ApiParam(value = "笔记id", example = "1") @PathVariable("id") Long id,
            @RequestBody LearningNoteFromDTO noteDTO) {
        noteDTO.setId(id);
        learningNoteService.updateNote(noteDTO);
    }
    /**
     * 采集笔记
     */
    @PostMapping("/notes/gathers/{id}")
    public void gatherNote(@PathVariable Long id) {

        learningNoteService.getNote(id);
    }
    /**
     * 取消采集
     */
    @DeleteMapping("/notes/gathers/{id}")
    public void deleteNote(@PathVariable Long id){
        learningNoteService.deleteNote(id);
    }

    @ApiOperation("删除笔记")
    @DeleteMapping("/{id}")
    public void removeMyNote(@ApiParam(value = "笔记id", example = "1") @PathVariable("id") Long id) {
        learningNoteService.deleteNote(id);
    }

    @GetMapping("/page")
    @ApiOperation("分页查询笔记")
    public PageDTO<LearningNoteVO> notePage(NoteQuery query) {
        return learningNoteService.notePage(query);
    }

}
